//
//  APPHUD.m
//  APP
//
//  Created by LXF on 2018/1/23.
//  Copyright © 2018年 Rdxer. All rights reserved.
//

#import "APHHUD.h"

@interface SVProgressHUD()

@property (nonatomic, strong) UIControl *controlView;

+ (SVProgressHUD*)sharedView;

-(UIView *)backgroundView;

- (UIColor*)backgroundColorForStyle;
- (UIColor*)foregroundColorForStyle;

- (void)fadeIn:(id)data;

@end



@implementation APHHUD

+(void)set_Loadinng_Style{
    
    [self setMinimumDismissTimeInterval:20];
    [self setImageViewSize:CGSizeMake(50, 50)];
    [self setBackgroundColor:[UIColor clearColor]];
    [self setDefaultMaskType:SVProgressHUDMaskTypeBlack];
}
+(void)set_Default_Style_NoDismis{
    [self setMinimumSize:CGSizeMake(100, 100)];
    [self setMinimumDismissTimeInterval:1.5];
    
    [self setDefaultMaskType:SVProgressHUDMaskTypeNone];
    
    [self setImageViewSize:CGSizeMake(28, 28)];
    
    [self setDefaultStyle:SVProgressHUDStyleDark];
    
    [self setBackgroundColor:[SVProgressHUD sharedView].backgroundColorForStyle];
    [self setDefaultStyle:SVProgressHUDStyleDark];
    
    [self setForegroundColor:[SVProgressHUD sharedView].foregroundColorForStyle];
    [self setDefaultStyle:SVProgressHUDStyleDark];
}
+(void)set_Default_Style{

//    HUD.setDefaultStyle(.dark)
//    HUD.setOffsetFromCenter(UIOffsetMake(0, 80))
//    HUD.setMinimumSize(.init(width: 100, height: 80))
//    HUD.setMinimumDismissTimeInterval(1.5)
    
    [self dismiss];
    [self set_Default_Style_NoDismis];
}

static UIImage *_APHHUD_image = nil;

+(void)setAPH_LoadingImage:(UIImage *)image{
    _APHHUD_image = image;
}

+ (void)show {
    [self set_Loadinng_Style];
    //[super showImage:[[UIImage alloc]init] status:nil];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showImage:_APHHUD_image status:nil];
    });
}


+ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
    [self set_Default_Style];
//    [super showWithStatus:status maskType:maskType];
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showWithStatus:status maskType:maskType];
    });
}

+ (void)showProgress:(float)progress {
//    [self set_Default_Style];
//    dispatch_async(dispatch_get_main_queue(), ^{
        [self showProgress:progress status:nil];
//    });
}

+ (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType {
//    [self set_Default_Style];
//
//    dispatch_async(dispatch_get_main_queue(), ^{
        [super showProgress:progress maskType:maskType];
//    });
}

+ (void)showProgress:(float)progress status:(NSString*)status {
//    [self set_Default_Style];
//    dispatch_async(dispatch_get_main_queue(), ^{
    [super showProgress:progress status:status];
//        });
}

+ (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
//    [self set_Default_Style];
//    dispatch_async(dispatch_get_main_queue(), ^{
    [super showProgress:progress status:status maskType:maskType];
//        });
}


#pragma mark - Show, then automatically dismiss methods

+ (void)showInfoWithStatus:(NSString*)status {
    [self set_Default_Style];
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showInfoWithStatus:status];
    });
}

+ (void)showInfoWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
    [self set_Default_Style];
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showInfoWithStatus:status maskType:maskType];
    });
}

+ (void)showSuccessWithStatus:(NSString*)status {
    [self set_Default_Style];
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showSuccessWithStatus:status];
    });
}

+ (void)showSuccessWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
    [self set_Default_Style];
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showSuccessWithStatus:status maskType:maskType];
    });
}

+ (void)showErrorWithStatus:(NSString*)status {
    [self set_Default_Style];
    dispatch_async(dispatch_get_main_queue(), ^{
        [super showErrorWithStatus:status];
    });
}

+ (void)showErrorWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
    [self set_Default_Style];
    dispatch_async(dispatch_get_main_queue(), ^{
    [super showErrorWithStatus:status maskType:maskType];
        });
}

+ (void)showImage:(UIImage*)image status:(NSString*)status {
    [self set_Default_Style];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [super showImage:image status:status];
        
    });
    
}

+ (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
    
    [self set_Default_Style];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [super showImage:image status:status maskType:maskType];
        
    });
    
}


- (void)fadeIn:(id)data {
    [super fadeIn:data];
    SVProgressHUD.sharedView.controlView.userInteractionEnabled = NO;
    SVProgressHUD.sharedView.backgroundView
    .userInteractionEnabled = NO;
}

+(void)dismiss{
    dispatch_async(dispatch_get_main_queue(), ^{
        [super dismiss];
    });
}

@end
